
'''
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
'''

'''
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.
    
    To request the provided software under a different license you can contact us at
    support@xoronos.com
'''

#####################################################
##                   Introduction                  ##
#####################################################
## This code example shows how to compute the ring ##
## signatures from a file.                         ##
##                                                 ##
## A ring signature algorithm, only the signer and ##
## verifier recognise the signature.               ##
##                                                 ##
## For an external observer or a decoy should be   ##
## unfeasible to understand the signer or verifier ## 
## of the signature. Furthermore, it should be not ##
## feasible to forge the signature ( impersonate   ##
## the signer ).                                   ##
#####################################################

#####################################################
##                   Pre-requisits                 ##
#####################################################
## The Xoron matrix decompressed data structure    ##
## needs to be mined before running this code      ##
## example. Some examples on how to mine Xoron     ##
## matrices can be found in                        ##
## generate_xrn_matrix_all_rnd.py or               ##
## generate_xrn_matrix_one_third.py                ##
##                                                 ##
## A monomial key for the signer.                  ##
## A binomial key for the signer.                  ##
## A monomial key for the verifier.                ##
## A binomial key for the verifier.                ##
## binomial keys for the decoys.                   ##
##                                                 ##
## An example on how to generate keys can be found ##
## in generate_keys_with_wrapper_functions.py      ##
#####################################################

import xrnlib256 as xrn

def generate_keys_file ( ):

    # used to create decoys
    decoy = xrn.xbinomial_key_t ( )
    xstart = xrn.xstart_point_t  ( )

    # library run time settings
    settings = xrn.xrn_crypto_extra_settings_t ()
    # all the subfields of settings, can be found in xrn_crypto_extra_settings_t.txt

    #############################
    ## Variable initialization ##
    #############################

    # Initialize default run time settings
    # In this code example only the settings.rnd_str is used
    # In the xrn_load_default_settings function xrn_make_start_point string is used.
    # Other functions names can be also used to initialize settings

    if ( xrn.XSUCCESS != xrn.xrn_load_default_settings( settings ) ) :
        return -1

    #################
    ## Start point ##
    #################

    print( "making start point ..." )

    start_point_fp = xrn.fopen( "start_point.xf", "wb" )
    decompressed_xrn_matrix_fp = xrn.fopen( "xrn_matrix.xm", "rb" )
    if (( start_point_fp == None ) or ( decompressed_xrn_matrix_fp == None ) ) :
        return -1

    if ( xrn.XSUCCESS != xrn.xrn_make_start_point_wrapper( start_point_fp, decompressed_xrn_matrix_fp, settings ) ) :
        xrn.fclose( start_point_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        return -1

    if (( 0 != xrn.fclose( start_point_fp ) ) or ( 0 != xrn.fclose( decompressed_xrn_matrix_fp ) ) ) :
        return -1

    #########################
    ## Monomial keys point ##
    #########################

    print( "making monomial keys ..." )

    signer_monomial_key_fp = xrn.fopen( "signer_monomial_key.xf", "wb" )
    if ( signer_monomial_key_fp == None ) :
        return -1

    if ( xrn.XSUCCESS != xrn.xrn_make_monomial_key_wrapper( signer_monomial_key_fp, settings ) ) :
        xrn.fclose( signer_monomial_key_fp )
        return -1

    if ( 0 != xrn.fclose( signer_monomial_key_fp ) ) :
        return -1

    verifier_monomial_key_fp = xrn.fopen( "verifier_monomial_key.xf", "wb" )
    if ( verifier_monomial_key_fp == None ) :
        return -1

    if ( xrn.XSUCCESS != xrn.xrn_make_monomial_key_wrapper( verifier_monomial_key_fp, settings ) ) :
        xrn.fclose( verifier_monomial_key_fp )
        return -1

    if ( 0 != xrn.fclose( verifier_monomial_key_fp ) ) :
        return -1

    #########################
    ## Binomial key signer ##
    #########################

    print( "making signer binomial keys ..." )

    start_point_fp = xrn.fopen( "start_point.xf", "rb" )
    decompressed_xrn_matrix_fp = xrn.fopen( "xrn_matrix.xm", "rb" )
    signer_monomial_key_fp = xrn.fopen( "signer_monomial_key.xf", "rb" )
    signer_binomial_key_fp = xrn.fopen( "signer_binomial_key.xf", "wb" )

    if (( start_point_fp == None ) or ( decompressed_xrn_matrix_fp == None ) or ( signer_monomial_key_fp == None ) or ( signer_binomial_key_fp == None ) ):
        return -1

    if ( xrn.XSUCCESS !=
         xrn.xrn_make_binomial_key_wrapper( decompressed_xrn_matrix_fp, start_point_fp, signer_monomial_key_fp,
                                     signer_binomial_key_fp, settings ) ) :
        xrn.fclose( signer_binomial_key_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( signer_monomial_key_fp )
        xrn.fclose( start_point_fp )
        return -1

    if ( ( 0 != xrn.fclose( signer_monomial_key_fp ) ) or ( 0 != xrn.fclose( signer_binomial_key_fp ) ) ) :
        return -1

    xrn.rewind( decompressed_xrn_matrix_fp )
    xrn.rewind( start_point_fp )

    ###########################
    ## Binomial key verifier ##
    ###########################

    print( "making verifier binomial keys ..." )

    verifier_monomial_key_fp = xrn.fopen( "verifier_monomial_key.xf", "rb" )
    verifier_binomial_key_fp = xrn.fopen( "verifier_binomial_key.xf", "wb" )
    if (( verifier_binomial_key_fp == None ) or ( verifier_monomial_key_fp == None ) ) :
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( start_point_fp )
        return -1

    if ( xrn.XSUCCESS !=
         xrn.xrn_make_binomial_key_wrapper( decompressed_xrn_matrix_fp, start_point_fp, verifier_monomial_key_fp,
                                     verifier_binomial_key_fp, settings ) ) :
        xrn.fclose( verifier_binomial_key_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( verifier_monomial_key_fp )
        xrn.fclose( start_point_fp )
        return -1

    if ( ( 0 != xrn.fclose( verifier_monomial_key_fp ) ) or ( 0 != xrn.fclose( verifier_binomial_key_fp ) )
         or ( 0 != xrn.fclose( decompressed_xrn_matrix_fp ) ) ) :
        return -1

    #######################
    ## Generating decoys ##
    #######################

    print( "making decoy 1 ..." )

    xrn.rewind( start_point_fp )

    if ( xrn.XSUCCESS != xrn.xrn_load_start_point( xstart, start_point_fp, settings ) ) :
        xrn.fclose( start_point_fp )
        return 1

    if ( 0 != xrn.fclose( start_point_fp ) ) :
        return 1

    decoy.start = xstart.start

    # first decoy

    xrn.xrn_initialize_true_rnd_num( settings.rnd_str, decoy.end )

    binomial_key_decoy_fp = xrn.fopen( "binomial_key_decoy_1.xf", "wb" )
    if ( binomial_key_decoy_fp == None ) :
        return 1

    if ( xrn.XSUCCESS != xrn.xrn_dump_binomial_key( decoy, binomial_key_decoy_fp, settings ) ) :
        xrn.fclose( binomial_key_decoy_fp )
        return 1

    if ( 0 != xrn.fclose( binomial_key_decoy_fp ) ) :
        return 1

    # second decoy

    print( "making decoy 2 ..." )

    xrn.xrn_initialize_true_rnd_num( settings.rnd_str, decoy.end )

    binomial_key_decoy_fp = xrn.fopen( "binomial_key_decoy_2.xf", "wb" )

    if ( binomial_key_decoy_fp == None ) :
        return 1

    if ( xrn.XSUCCESS != xrn.xrn_dump_binomial_key( decoy, binomial_key_decoy_fp, settings ) ) :
        xrn.fclose( binomial_key_decoy_fp )
        return 1

    if ( 0 != xrn.fclose( binomial_key_decoy_fp ) ) :
        return 1

    # third decoy

    print( "making decoy 3 ..." )

    xrn.xrn_initialize_true_rnd_num( settings.rnd_str, decoy.end )

    binomial_key_decoy_fp = xrn.fopen( "binomial_key_decoy_3.xf", "wb" )

    if ( binomial_key_decoy_fp == None ) :
        return 1

    if ( xrn.XSUCCESS != xrn.xrn_dump_binomial_key( decoy, binomial_key_decoy_fp, settings ) ) :
        xrn.fclose( binomial_key_decoy_fp )
        return 1

    if ( 0 != xrn.fclose( binomial_key_decoy_fp ) ) :
        return 1

    # fourth decoy

    print( "making decoy 4 ..." )

    xrn.xrn_initialize_true_rnd_num( settings.rnd_str, decoy.end )

    binomial_key_decoy_fp = xrn.fopen( "binomial_key_decoy_4.xf", "wb" )

    if ( binomial_key_decoy_fp == None ) :
        return 1

    if ( xrn.XSUCCESS != xrn.xrn_dump_binomial_key( decoy, binomial_key_decoy_fp, settings ) ) :
        xrn.fclose( binomial_key_decoy_fp )
        return 1

    if ( 0 != xrn.fclose( binomial_key_decoy_fp ) ) :
        return 1

    return 0


def xrn_generate_ring_signature_wrapper_example ( ):

    #########################
    ## Variable definition ##
    #########################

    # library run time settings
    settings = xrn.xrn_crypto_extra_settings_t ( )
    # all the subfields of settings, can be found in xrn_crypto_extra_settings_t.txt

    #############################
    ## Variable initialization ##
    #############################

    # Initialize default run time settings
    # In this code example only the settings.rnd_str is used
    # In the xrn_load_default_settings function xrn_make_start_point string is used.
    # Other functions names can be also used to initialize settings

    if ( xrn.XSUCCESS != xrn.xrn_load_default_settings( settings ) ) :
        return -1

    ndecoys = 2
    binomial_key_decoys_fp = xrn.new_FILEp_array(ndecoys)

    if ( binomial_key_decoys_fp == None ) :
        return -1

    signer_monomial_key_fp = xrn.fopen( "signer_monomial_key.xf", "rb" )
    signer_binomial_key_fp = xrn.fopen( "signer_binomial_key.xf", "rb" )
    verifier_binomial_key_fp = xrn.fopen( "verifier_binomial_key.xf", "rb" )
    decompressed_xrn_matrix_fp = xrn.fopen( "xrn_matrix.xm", "rb" )
    ring_signature_fp = xrn.fopen( "ring_signature.xf", "wb" )
    xrn.FILEp_array_setitem( binomial_key_decoys_fp,0,xrn.fopen( "binomial_key_decoy_1.xf", "rb" ))
    xrn.FILEp_array_setitem( binomial_key_decoys_fp,1,xrn.fopen( "binomial_key_decoy_2.xf", "rb" ))
    input_file_fp = xrn.fopen( "lorem_ipsum.txt", "rb" )

    if (( signer_monomial_key_fp == None ) or ( signer_binomial_key_fp == None ) or 
        ( verifier_binomial_key_fp == None ) or ( decompressed_xrn_matrix_fp == None ) or 
        ( ring_signature_fp == None ) or ( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0) == None ) or 
        ( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1) == None ) or ( input_file_fp == None ) ):
        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1

    ####################
    ## Ring signature ##
    ####################

    if ( xrn.XSUCCESS != xrn.xrn_make_ring_signature_wrapper( input_file_fp,   # input file
                                               binomial_key_decoys_fp,  # list of decoys file pointers
                                               signer_monomial_key_fp,  # monomial key of the signer file pointer
                                               signer_binomial_key_fp,  # binomial key of the signer file pointer
                                               verifier_binomial_key_fp,        # binomial key of the verifier file pointer
                                               decompressed_xrn_matrix_fp,    # Xoron matrix file pointer
                                               ndecoys, # number of decoys (length of the file pointer array of binomial_key_decoys_fp)
                                               ring_signature_fp,       # output ring signature file pointers
                                               settings # run time settings
          ) ) :

        xrn.fclose( input_file_fp )
        xrn.fclose( ring_signature_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( verifier_binomial_key_fp )
        xrn.fclose( signer_binomial_key_fp )
        xrn.fclose( signer_monomial_key_fp )
        xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0)  )
        xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1)  )
        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1

    if ( ( xrn.fclose( input_file_fp ) != 0 ) or ( xrn.fclose( ring_signature_fp ) != 0 )
         or ( xrn.fclose( decompressed_xrn_matrix_fp ) != 0 ) or ( xrn.fclose( verifier_binomial_key_fp ) != 0 )
         or ( xrn.fclose( signer_binomial_key_fp ) != 0 ) or ( xrn.fclose( signer_monomial_key_fp ) != 0 )
         or ( xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0)  ) )
         or ( xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1)  ) )) :

        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1

    # An alternative way to perform the same computation can be achieved using the xrn_make_ring_signature function
    # if ( xrn.XSUCCESS != xrn.xrn_make_ring_signature ( input_file_fp,
    #                                    binomial_key_decoys, # binomial_key_decoys is of the type ( xbinomial_key_t * )
    #                                    signer_monomial_key, # signer_monomial_key is of the type ( xmonomial_key_t )
    #                                    signer_binomial_key, # signer_binomial_key is of the type ( xbinomial_key_t )
    #                                    verifier_binomial_key, # verifier_binomial_key is of the type ( xbinomial_key_t )
    #                                    xrn_matrix, # Xoron matrix is of the type ( xrn_matrix_t * )
    #                                    ndecoys,
    #                                    ring_signature , # ring_signature is of the type ( xring_signature_t * )
    #                                    settings
    #       ) ) :

    ######################################
    ## Emulated Received Ring signature ##
    ######################################

    ## To keep the same decoys of a previously received ring signature use the following function
    ## In this example we regenerate a new ring signature instead of receiving one


    signer_monomial_key_fp = xrn.fopen( "signer_monomial_key.xf", "rb" )
    signer_binomial_key_fp = xrn.fopen( "signer_binomial_key.xf", "rb" )
    verifier_binomial_key_fp = xrn.fopen( "verifier_binomial_key.xf", "rb" )
    decompressed_xrn_matrix_fp = xrn.fopen( "xrn_matrix.xm", "rb" )
    redundant_ring_signature_fp = xrn.fopen( "redundant_ring_signature.xf", "wb" )
    xrn.FILEp_array_setitem( binomial_key_decoys_fp,0,xrn.fopen( "binomial_key_decoy_3.xf", "rb" ))
    xrn.FILEp_array_setitem( binomial_key_decoys_fp,1,xrn.fopen( "binomial_key_decoy_4.xf", "rb" ))
    input_file_fp = xrn.fopen( "lorem_ipsum.txt", "rb" )

    if (( signer_monomial_key_fp == None ) or ( signer_binomial_key_fp == None ) or 
        ( verifier_binomial_key_fp == None ) or ( decompressed_xrn_matrix_fp == None ) or 
        ( redundant_ring_signature_fp == None ) or ( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0) == None ) or 
        ( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1) == None ) or ( input_file_fp == None ) ):
        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1


    if ( xrn.XSUCCESS != xrn.xrn_make_ring_signature_wrapper( input_file_fp,   # input file
                                               binomial_key_decoys_fp,  # list of decoys file pointers
                                               signer_monomial_key_fp,  # monomial key of the signer file pointer
                                               signer_binomial_key_fp,  # binomial key of the signer file pointer
                                               verifier_binomial_key_fp,        # binomial key of the verifier file pointer
                                               decompressed_xrn_matrix_fp,    # Xoron matrix file pointer
                                               ndecoys, # number of decoys (length of the file pointer array of binomial_key_decoys_fp)
                                               redundant_ring_signature_fp,       # output ring signature file pointers
                                               settings # run time settings
          ) ) :

        xrn.fclose( input_file_fp )
        xrn.fclose( redundant_ring_signature_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( verifier_binomial_key_fp )
        xrn.fclose( signer_binomial_key_fp )
        xrn.fclose( signer_monomial_key_fp )
        xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0)  )
        xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1)  )
        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1

    if ( ( xrn.fclose( input_file_fp ) != 0 ) or ( xrn.fclose( redundant_ring_signature_fp ) != 0 )
         or ( xrn.fclose( decompressed_xrn_matrix_fp ) != 0 ) or ( xrn.fclose( verifier_binomial_key_fp ) != 0 )
         or ( xrn.fclose( signer_binomial_key_fp ) != 0 ) or ( xrn.fclose( signer_monomial_key_fp ) != 0 )
         or ( xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,0)  ) )
         or ( xrn.fclose( xrn.FILEp_array_getitem ( binomial_key_decoys_fp,1)  ) )) :

        xrn.delete_FILEp_array( binomial_key_decoys_fp )
        return -1

    xrn.delete_FILEp_array( binomial_key_decoys_fp )

    ############################
    ## Permute Ring signature ##
    ############################

    signer_binomial_key_fp = xrn.fopen( "signer_binomial_key.xf", "rb" )
    verifier_binomial_key_fp = xrn.fopen( "verifier_binomial_key.xf", "rb" )
    redundant_ring_signature_fp = xrn.fopen( "redundant_ring_signature.xf", "rb" )
    ring_signature_fp = xrn.fopen( "redundant_ring_signature.xf", "rb" )
    permuted_ring_signature_fp = xrn.fopen( "permuted_ring_signature.xf", "wb" )

    if ( ( signer_binomial_key_fp == None ) or ( verifier_binomial_key_fp == None ) or
         ( redundant_ring_signature_fp == None ) or ( ring_signature_fp == None ) or
         ( permuted_ring_signature_fp == None ) ):
        return -1

    if ( xrn.XSUCCESS != xrn.xrn_permute_ring_signature_wrapper( signer_binomial_key_fp, # the signer binomial key
                                                         verifier_binomial_key_fp, # the verifier binomial key
                                                         redundant_ring_signature_fp, # the signer ring signature
                                                         ring_signature_fp, # the verifier ring signature
                                                         permuted_ring_signature_fp, # the permuted ring signature
                                                         settings ) ) :

        if ( ( xrn.fclose( signer_binomial_key_fp ) != 0 ) or ( xrn.fclose( verifier_binomial_key_fp ) != 0 ) or 
             ( xrn.fclose( redundant_ring_signature_fp ) != 0 ) or ( xrn.fclose( ring_signature_fp ) != 0 ) or 
             ( xrn.fclose( permuted_ring_signature_fp ) != 0 ) ) :
            return -1

    if ( ( xrn.fclose( signer_binomial_key_fp ) != 0 ) or ( xrn.fclose( verifier_binomial_key_fp ) != 0 ) or 
         ( xrn.fclose( redundant_ring_signature_fp ) != 0 ) or ( xrn.fclose( ring_signature_fp ) != 0 ) or 
         ( xrn.fclose( permuted_ring_signature_fp ) != 0 ) ) :
        return -1

    return 0


def xrn_verify_ring_signature_wrapper_example ( ) :

    #########################
    ## Variable definition ##
    #########################

    # library run time settings
    settings = xrn.xrn_crypto_extra_settings_t ( )
    # all the subfields of settings, can be found in xrn_crypto_extra_settings_t.txt

    #############################
    ## Variable initialization ##
    #############################

    # Initialize default run time settings
    # In this code example only the settings.rnd_str is used
    # In the xrn_load_default_settings function xrn_make_start_point string is used.
    # Other functions names can be also used to initialize settings

    if ( xrn.XSUCCESS != xrn.xrn_load_default_settings( settings ) ) :
        return -1

    verifier_monomial_key_fp = xrn.fopen( "verifier_monomial_key.xf", "rb" )
    signer_binomial_key_fp = xrn.fopen( "signer_binomial_key_from_verifier.xf", "wb" )
    decompressed_xrn_matrix_fp = xrn.fopen( "xrn_matrix.xm", "rb" )
    ring_signature_fp = xrn.fopen( "permuted_ring_signature.xf", "rb" )
    input_file_fp = xrn.fopen( "lorem_ipsum.txt", "rb" )

    if (( verifier_monomial_key_fp == None ) or ( signer_binomial_key_fp == None ) or ( decompressed_xrn_matrix_fp == None ) or ( ring_signature_fp == None ) or ( input_file_fp == None ) ):
        return -1

    ####################
    ## Ring signature ##
    ####################

    if ( xrn.XSUCCESS != xrn.xrn_check_ring_signature_wrapper( input_file_fp,   # input file
                                               ring_signature_fp,       # ring signature file pointers
                                               verifier_monomial_key_fp,        # monomial key of the verifier file pointer
                                               decompressed_xrn_matrix_fp,    # Xoron matrix file pointer
                                               signer_binomial_key_fp,  # binomial key of the signer file pointer
                                               settings # run time settings
          ) ) :

        xrn.fclose( input_file_fp )
        xrn.fclose( ring_signature_fp )
        xrn.fclose( decompressed_xrn_matrix_fp )
        xrn.fclose( signer_binomial_key_fp )
        xrn.fclose( verifier_monomial_key_fp )
        return -1


    if ( ( xrn.fclose( input_file_fp ) != 0 ) or ( xrn.fclose( ring_signature_fp ) != 0 )
         or ( xrn.fclose( decompressed_xrn_matrix_fp ) != 0 ) or ( xrn.fclose( signer_binomial_key_fp ) != 0 )
         or ( xrn.fclose( verifier_monomial_key_fp ) != 0 ) ) :
        return -1

    # An alternative way to perform the same computation can be achieved using the xrn_check_ring_signature function
    # if ( xrn.XSUCCESS != xrn.xrn_check_ring_signature( input_file_fp,
    #                                   ring_signature, # ring_signature is of the type ( xring_signature_t )
    #                                   verifier_monomial_key, # verifier_monomial_key is of the type ( xmonomial_key_t )
    #                                   xrn_matrix, # Xoron matrix is of the type ( xrn_matrix_t * )
    #                                   signer_binomial_key, # signer_binomial_key is of the type ( xbinomial_key_t * )
    #                                   settings
    #       ) ) :

    return 0


#############
## Logging ##
#############

# Set the default logging file streams
# errors -> stderr
# warnings -> stdout
# notifications -> stdout
# debug -> stdout

xrn.xrn_set_default_log(  )

# To change the default logging you can use the functions below,
# where fp is the opened file pointer
# 
# xrn_change_error_log( fp )
# xrn_change_warning_log( fp )
# xrn_change_notification_log( fp )
# xrn_change_debug_log( fp )

if ( 0 != generate_keys_file(  ) ) :
    exit( -1 )

print( "making ring signature ... " )
if ( 0 != xrn_generate_ring_signature_wrapper_example(  ) ) :
    print( "error in signature " )
    exit( -1 )

print( "verify ring signature ... " )
if ( 0 != xrn_verify_ring_signature_wrapper_example(  ) ) :
    print( "signature does not match" )
    exit( -1 )
else :
    print( "signature does match" )

exit( 0 )



